package com.spzx.channel.service.impl;

import com.spzx.channel.service.IndexService;
import com.spzx.common.core.constant.SecurityConstants;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.exception.ServiceException;
import com.spzx.product.api.CategoryFeignClient;
import com.spzx.product.api.ProductSkuFeignClient;
import com.spzx.product.api.domain.ProductSku;
import com.spzx.product.api.domain.vo.CategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName IndexServiceImpl
 * @Author 波
 * @Date 2024/8/4 11:23
 */
@Service
public class IndexServiceImpl implements IndexService {

    @Autowired
    private CategoryFeignClient categoryFeignClient;
    @Autowired
    private ProductSkuFeignClient productSkuFeignClient;

    @Override
    public Map<String, Object> getIndexData() {
        R<List<CategoryVo>> categoryVoList = categoryFeignClient.getOneCategory(SecurityConstants.INNER);
        if(R.FAIL==categoryVoList.getCode()){
            throw new ServiceException(categoryVoList.getMsg());
        }
        R<List<ProductSku>> productSkuList = productSkuFeignClient.getTopSale(SecurityConstants.INNER);
        if(R.FAIL==productSkuList.getCode()){
            throw new ServiceException(productSkuList.getMsg());
        }
        Map<String, Object> map = new HashMap<>();
        map.put("categoryList", categoryVoList.getData());
        map.put("productSkuList", productSkuList.getData());
        return map;
    }
}
